﻿using System;
using System.Collections.Generic;
using System.Reactive.Linq;
using Moq;
using NUnit.Framework;
using Wombat.Core.Services;
using Wombat.Data;
using Wombat.Data.Model;

namespace Data.UnitTests
{
    [TestFixture]
    public class StreamRepositoryUnitTests
    {
        [Test]
        public void InsertSingular()
        {
            var ds = new Mock<IDataService>();

            var repo = new StreamRepository(ds.Object);
            var v = new Mock<ITimed<float>>();
            ds.Setup(s => s.InsertFloatData(It.IsAny<FloatData>()))
                .Verifiable();

            repo.InsertStream(Observable.Return(v.Object));
            ds.VerifyAll();
        }

        [Test]
        public void InsertBulk()
        {
            var ds = new Mock<IDataService>();
            var repo = new StreamRepository(ds.Object)
                           {
                               BulkInsert = true,
                               BulkInsertQueueLength = 1,
                               BulkInsertQueueTime = TimeSpan.FromMilliseconds(10)
                           };
            var v = new Mock<ITimed<float>>();
            ds.Setup(s => s.BulkInsertFloatData(It.IsAny<IEnumerable<FloatData>>()))
                .Verifiable();

            repo.InsertStream(Observable.Return(v.Object));
            ds.VerifyAll();
        }
    }
}
